<?php $pageName="scenario";?>
<?php require_once('header.php'); ?>    
  

<div class="repCont brd">

<?php     
$scnId  = trim( Request::getVar('scnId') ); // (isset($_GET['scnId']))? $_GET['scnId']:"" ; 
$action  = trim( Request::getVar('scnAct') ); //(isset($_GET['scnAct']))? $_GET['scnAct']:"" ; 

$wella = new Base();

if ($action=='save' || $action=='update'){
      

        
        
       // echo "save";

            $scnTitle  = trim( Request::getVar('scnTitle') );
            $scnDesc  = trim( Request::getVar('scnDesc') );
            $scnReports  = trim( Request::getVar('scnReports') );
            $scnId  = ( Request::getVar('scnId') )? trim( Request::getVar('scnId') ): 0;
            
                                                                                  
           
           
            $wella->saveScenario($scnId,$scnTitle,$scnDesc,$scnReports, 'save'); 
            
            
          

   
   
    
}

//else{

 if ((intval($scnId)>0) && $action=='editScn'){
    
 $scnObj  = $wella->getScenarios($scnId) ;
 
 $scnTitle    = $scnObj[0][1];  
 $scnDesc    = $scnObj[0][2];
 $scnReports    = $scnObj[0][3];
 //var_dump($scnObj) ;
    
?>                                                                                      
 <form method="post" action="showScenario.php" id="scnForm" enctype="multipart/form-data"> 
            <fieldset> 
            
            <input type="hidden" id="scnId" name="scnId" value="<?php echo $scnId;?>" /> 
            <input type="hidden" id="scnReports" name="scnReports" value="<?php echo $scnReports;?>" /> 
            
            <input type="hidden" id="scnAct" name="scnAct" value="save" /> 
            

                <div class="fItem">
                    <span for="">Edit  Scenario:  </span>
                    
                </div>
                
                <div class="fItem">
                    <label for="rTitle">Scenario Title:</label>
                    <input type="text" id="scnTitle" name="scnTitle"  value="<?php echo $scnTitle;?>" />
                </div>

                <div class="fItem">
                    <label for="rDesc">Scenario Description:</label>
                    <textarea id="scnDesc" name="scnDesc" class"tArea"><?php echo $scnDesc;?></textarea>
                </div>

                <div class="fItem">
                    <label for="rUrl">Scenario Steps: </label>
                    <div class="scn-list">
<?php
   $reports = $wella->getReports();
   //var_dump($reports);
   $scnReportsSelected = explode(',',$scnReports)  ;
   
   if (sizeof($reports)>0){
       foreach($reports as $report)   {
        $strChecked = '';
        if (in_array($report[0],$scnReportsSelected ) ){
        $strChecked = ' checked="checked"';
        }
?>

                        
                        <div class="fItem"> 
                        <input type="checkbox" class="bChk" id="scnRep_<?php echo $report[0];?>" name="scnRep_<?php echo $report[0];?>"  value="<?php echo $report[0];?>"<?php echo $strChecked;?> /> <label for="scnRep_<?php echo $report[0];?>"> <?php echo $report[1];?></label><br />
                        </div>  
                        
<?php
       }
   }
?>
                         
                    </div> 
                </div>

               

                <div class="fItem actButCont">  
                <div class="rgt">                                                                       
                    <input type="button" class="actbutton" id="scnDelete" name="scnDelete" value="Delete" />
                    <input type="reset" class="actbutton" id="scnCancel" name="scnCancel" value="Cancel" />
                    <input type="button" class="actbutton" id="scnSubmit" name="scnSubmit" value="Save" />
                </div>
                </div>

            </fieldset>

  </form>
  

<?php
    
    
}else if (intval($scnId)>0){
   //print_r($from_post);
   
   
    switch($action){
        
                       
        case 'delete':
         $wella->deleteScenario($scnId); 
        
        break;  
             
      
        default:
            $wella->showScenario($scnId, '');
        break;     
      
        
    }
    
}else if($action=='addNew'){
    
    
 ?>                       
 <form method="post" action="showScenario.php" id="scnForm" enctype="multipart/form-data"> 
            <fieldset> 
            
            <input type="hidden" id="scnId" name="scnId" value="" /> 
            <input type="hidden" id="scnReports" name="scnReports" value="" /> 
            
            <input type="hidden" id="scnAct" name="scnAct" value="save" /> 
            

                <div class="fItem">
                    <span for="">Add New  Scenario:  </span>
                    
                </div>
                
                <div class="fItem">
                    <label for="rTitle">Scenario Title:</label>
                    <input type="text" id="scnTitle" name="scnTitle"  value=""/>
                </div>

                <div class="fItem">
                    <label for="rDesc">Scenario Description:</label>
                    <textarea id="scnDesc" name="scnDesc" class"tArea"></textarea>
                </div>

                <div class="fItem">
                    <label for="rUrl">Scenario Steps </label>
                    <div class="scn-list brd">
<?php
   $reports = $wella->getReports();
   //var_dump($reports);
   
   if (sizeof($reports)>0){
       foreach($reports as $report)   {
?>
                        
                        <div class="fItem"> 
                        <input type="checkbox" class="bChk" id="scnRep_<?php echo $report[0];?>" name="scnRep_<?php echo $report[0];?>"  value="<?php echo $report[0];?>"/> <label for="scnRep_<?php echo $report[0];?>"> <?php echo $report[1];?></label><br />
                        </div>  
                        
<?php
       }
   }
?>
                         
                    </div> 
                </div>

               

                <div class="fItem actButCont">  
                <div class="rgt">                                                                       
                    <input type="button" class="actbutton" id="scnSubmit" name="scnSubmit" value="Save" />
                </div>
                </div>

            </fieldset>

  </form>
  

 <?php
    
 
   
}else{
?>

<h2>Scenarios: </h2><br/>

<?php     
      //print_r($from_post);
   $wella = new Base();
   $wella->showScenarioLinks();

?>  

<?php
    
}
//}
?>
 <?php require_once('links.php'); ?>  



</div>  

 
<?php require_once('footer.php'); ?>   
